<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <div class="slideTxtBox">
	<div class="hd">
		<ul><li>当年茶</li><li>新茶</li><li>中期茶</li></ul>
	</div>
	<div class="bar">
		<ul>
			<li>品名</li>
			<li>参考价</li>
			<li>升跌</li>
		</ul>
	</div>				
	<div class="bd">
		<ul>
			<li>
				<div class="txtScroll-top" id="scrollDiv5">
				    <div class="bd2">
				        <ul class="infoList">
				        
						</ul>
				    </div>
				</div>
			</li>
		</ul>
		<ul>
			<li>
				<div class="txtScroll-top" id="scrollDiv6">
				    <div class="bd2">
				        <ul class="infoList">
						</ul>
				    </div>
				</div>
			</li>
		</ul>
		<ul>
			<li>
				<div class="txtScroll-top" id="scrollDiv7">
				    <div class="bd2">
				        <ul class="infoList">
						</ul>
				    </div>
				</div>
			</li>
		</ul>
	</div>
</div>
<script type="text/javascript">

</script>

<script>
$(function(){
	
	function loadData() {
		request(5).then(() => {
			return request(6);
		}).then(() => {
			return request(7);
		}).then(() => {
			$(".slideTxtBox").slide({autoPlay:true,interTime:20000});
		});
	}
	
	function request(type) {
		
		return new Promise((rs, rj) => {
			$.get(
					'http://39.108.102.54/api/Investment/getGoodsList/'+type,
					{}, 
					function(json) {
						if (json['code'] == 1) {
							for (var i = 0; i < json['data'].length; i++) {
								let item = json['data'][i];
								var cls = '';
								var prefix = '';
								if(item['changePrice'] > 0) {
									cls = 'red';
									prefix = '升';
								} else if (item['changePrice'] < 0) {
									cls = 'green';
									prefix = '降价';
								}
								var changePrice = prefix + '¥' + Math.abs(item['changePrice']);
								
								var pref = '';
								if(item['percent'] > 0) {
									pref = '↑';
								} else if(item['percent'] < 0) {
									pref = '↓';
								}
								
								var percent = pref+ Math.abs(item['percent']) + '%';
								
								var li = "<li>"+
											"<span class='name'>"+item['goodsName']+"</span>"+
											"<span class='price'>"+item['format_price']+"</span>"+
											"<span class='u_price "+cls+"'>"+changePrice+"</span>"+
											"<span class='percent "+cls+"'>"+percent+"</span>"+
										 "</li>";
								$('#scrollDiv'+type+' .infoList').append(li);
							}
							rs();
						} else {
							rj(json['msg']);
						}
						$("#scrollDiv"+type).slide({mainCell:".bd2 ul",autoPage:true,effect:"topLoop",autoPlay:true,vis:20,delayTime:1000});
					},
				"json");
		});
	}
	
	loadData();
	
});
</script>